package com.bsxwl.config;

import com.bsxwl.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 将 MyInterceptor 自定义拦截器注册到 spring ioc 容器
     * Register MyInterceptor custom interceptor with spring ioc container.
     * @return
     */
    @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

    /**
     * Override this method; Add custom interceptor to interceptor.
     * @param registry interceptor chain
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //通过registry添加MyInterceptor拦截器，并设置拦截器路径为 /*
        registry.addInterceptor(myInterceptor()).addPathPatterns("/*");
    }
}
